#ifdef a
//写一个完整的日期类
#include<iostream>
using namespace std;
class Date {
public:
	//构造函数
	Date(const int day = 2, const int month = 9, const int year = 2022)
	:_day(day)
	,_month(month)
	,_year(year)
	{
		//保证合法性
		if (!(_year > 0 && _month > 0 && _month <= 12 && _day > 0 && _day < GetDay(_year, _month))) {
			_year = 2022;
			_month = 9;
			_day = 2;
		}
	}
	int GetDay(const int year, const int month)const {
		int days[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		if (LeadYear(year))
			days[1] += 1;
		return days[month];
	}
	bool LeadYear(const int year)const {
		return ((!(year % 4) && (year % 100)) || !(year % 400));
	}
	//析构函数
	~Date() {
		//_day = -1;
		//_month = -1;
		//_year = -1;
	}
		
	//拷贝构造
	Date(const Date& d)
		:_year(d._year)
		,_month(d._month)
		,_day(d._day)
	{}

	//赋值运算符重载
	Date& operator=(const Date& d) {
		if (this != &d) {
			_year = d._year;
			_month = d._month;
			_day = d._day;
		}
		return *this;
	}

	//取地址重载
	Date* operator&() {
		return this;
	}

	//const取地址重载
	const Date* operator&()const {
		return this;
	}

	//后置++
	Date& operator++(int) {
		Date temp(*this);
		*this = *this + 1;
		return temp;
	}
	//前置++
	Date& operator++() {
		*this = *this + 1;
		return *this;
	}

	//后置--
	Date& operator--(int) {
		Date temp(*this);
		*this = *this - 1;
		return temp;
	}

	//前置--
	Date& operator--() {
		*this = *this - 1;
		return *this;
	}

	//+(n天后)
	Date& operator+(const int days) {
		if (days < 0)
			return *this - (0 - days);
		Date temp(*this);
		temp._day += days;
		while (temp._day > GetDay(_year, _month)) {
			temp._day -= GetDay(_year, _month);
			temp._month++;
			if (temp._month > 12) {
				temp._month = 1;
				temp._year++;
			}
		}
		return temp;
	}

	//日期之间的间隔
	const int operator-(const Date& d)const {
		Date min_date(d);
		Date max_date(*this);
		int count = 0;
		if (d > *this) {
			min_date = *this;
			max_date = d;
		}
		while (min_date < max_date) {
			min_date++;
			count++;
		}
		return count;
	}
	//-(n天前)
	Date& operator-(const int days) {
		if (days < 0)
			return *this + (0 - days);
		Date temp(*this);
		temp._day -= days;
		while (temp._day <= 0) {
			temp._month--;
			if (temp._month <= 0) {
				temp._month = 12;
				temp._year--;
			}
			temp._day += GetDay(_year, _month);
		}
		return temp;
	}
	//==
	bool operator==(const Date& d)const {
		return  (_day == d._day) &&
				(_month == d._month) &&
				(_year == d._year);
	}
	//!=
	bool operator!=(const Date& d)const {
		return !(*this == d);
	}
	//>
	bool operator>(const Date& d)const {
		return  (_year > d._year) ||
				(_year == d._year && _month > d._month) ||
				(_year == d._year && _month == d._month && _day > d._day);
	}
	//< 
	bool operator<(const Date& d)const {
		return !((*this > d) || (*this == d));
	}

	//打印测试
	void Print() {
		cout << _year << '.' << _month << '.' << _day << endl;
	}
private:
	int _day;
	int _month;
	int _year;
};


void TestDate() {
	/*
	Date d1(1, 2, 3);
	const Date d2(4, 5, 6);
	//const对象同样可以调用构造/析构等函数
	*/
	//const对象是否可以调用赋值运算符重载函数/前置++---》肯定不能


	//测试
	Date d1;
	cout << "d1 :";
	d1.Print();
	Date d2(d1);
	cout << "d2 :";
	d2.Print();
	Date d3(3, 9, 2022);
	cout << "d3 :";
	d3.Print();

	Date after_date = d2 + 5;
	after_date.Print();

	Date before_date = d1 - 5;
	before_date.Print();

	cout << endl;
	cout << d3 - d2 << endl;
}
int main() {
	TestDate();
	return 0;
}
#endif 
